﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PackCreaterView.xaml.cs" company="R.V.Kasner">
//   Copyright © 2011 R.V.Kasner
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Owen.Terminal.View
{
    using System;

    using Owen.Terminal.ViewModel;

    /// <summary>
    ///   Логика взаимодействия для PackCreaterView.xaml
    /// </summary>
    public partial class PackCreaterView : IPackCreaterView
    {
        private bool isSelected;

        public PackCreaterView()
        {
            this.InitializeComponent();
        }

        public event Action Selected;

        public bool IsSelected
        {
            get
            {
                return this.isSelected;
            }

            set
            {
                this.isSelected = value;
                if (this.isSelected)
                {
                    this.RaiseSelected();
                }
            }
        }

        public string Title
        {
            get
            {
                return "Создание пакета";
            }
        }

        public IPackCreaterViewModel ViewModel
        {
            get
            {
                return this.DataContext as IPackCreaterViewModel;
            }

            set
            {
                if (this.DataContext == value)
                {
                    return;
                }

                this.DataContext = value;
            }
        }

        IViewModel IView.ViewModel
        {
            get
            {
                return this.ViewModel;
            }

            set
            {
                this.ViewModel = value as IPackCreaterViewModel;
            }
        }

        public void RaiseSelected()
        {
            var handler = this.Selected;
            if (handler != null)
            {
                handler();
            }
        }
    }
}